package com.taru.houseapp.service.impl;

import com.taru.houseapp.dao.IHouseDao;
import com.taru.houseapp.entity.*;
import com.taru.houseapp.service.IHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class HouseServiceImpl implements IHouseService {

    @Autowired
    IHouseDao houseDao;

    @Override
    @Transactional(rollbackFor = java.lang.Exception.class)
    public String insertHouse(House house) {
        houseDao.insertHouse(house);
        Device device=house.getDevices();
        device.setHouseId(house.getId());
        houseDao.inertHouseDevice(device);
        houseDao.insertHouseImage(house);
        return house.getId();
    }

    @Override
    public int deleteHouseImage(List<Integer> ids) {

        return houseDao.deleteHouseImage(ids);
    }

    @Override
    @Transactional(rollbackFor = java.lang.Exception.class)
    public int updateHouse(House house) {
        int code1=0;
        int code2=0;
        code1= houseDao.updateHouse(house);
        code2=houseDao.updateHouseDevice(house.getDevices());
        return code1 & code2;
    }

    @Override
    public int updateHouseIsHot(House house) {

        return houseDao.updateHouseIsHot(house);
    }

    @Override
    public int updateHouseIsRent(House house) {

        return houseDao.updateHouseIsRent(house);
    }

    @Override
    public int updateHouseIsShelf(House house) {

        return houseDao.updateHouseIsShelf(house);
    }

    @Override
    public House queryHouseById(String id) {

        return houseDao.queryHouseById(id);
    }

    @Override
    public List<House> queryHouseByUserId(String userId, String code) {

        return houseDao.queryHouseByUserId(userId,code);
    }


    @Override
    public House queryHouseByIdRenter(String id) {

        return houseDao.queryHouseByIdRenter(id);
    }

    @Override
    public boolean queryIsCollectionHouse(VoHouseColl voHouseColl) {
        VoHouseColl voHouseColl1=houseDao.queryIsCollectionHouse(voHouseColl);
        boolean isCollection=false;
        if(voHouseColl1!=null){
            isCollection=true;
        }
        return isCollection;
    }

    @Override
    public int insertCollectionHouse(VoHouseColl voHouseColl) {

        return houseDao.insertCollectionHouse(voHouseColl);
    }

    @Override
    public int deletedCollectionHouse(VoHouseColl voHouseColl) {

        return houseDao.deletedCollectionHouse(voHouseColl);
    }


    @Override
    public House queryHouseAndRentOutUser(String houseId) {

        return houseDao.queryHouseAndRentOutUser(houseId);
    }

    @Override
    public List<House> queryHouseByCategory(String city, String villageName,String code,String orderNumber) {

        return houseDao.queryHouseByCategory(city,villageName,code,orderNumber);
    }

    @Override
    public List<House> queryCollectionHouse(String userId, String code) {

        return houseDao.queryCollectionHouse(userId,code);
    }

    @Override
    public List<House> queryHouseByHot(String city) {

        return houseDao.queryHouseByHot(city);
    }

    @Override
    public List<House> queryHouseByCommon(String city) {

        return houseDao.queryHouseByCommon(city);
    }
}
